import {get, post} from "./Request.ts";
import {
    ADD_ORDER_URL,
    CATEGORY_URL, CHOICE_URL,
    DETAIL_URL, FOOTER_TAG_URL,
    FOOTER_URL,
    Head, HOME_URL, HOT_URL,
    RAN_URL, RECOMMEND_URL,
    SEARCH_URL,
    SORT_URL
} from "./api.ts";

/**
 * 轮播图
 */
export const fetchBanner = <T = any>(params?: Record<string, any>) => {
    return get<T>(HOME_URL,params);
}
/**
 * 数据
 */
export const fetchHomeData = <T = any>(id: number) => {
    return get<T>(`${RECOMMEND_URL}/${id}`);
}

/**
 *  获取分类列表
 */
export const fetchCategoryList = <T = any>(params?: Record<string, any>) => {
    return get<T>(CATEGORY_URL, params);
}

/**
 * 获取產品详情
 */
export const fetchProductDetail = <T = any>(params?: Record<string, any>) => {
    return get<T>(DETAIL_URL, params);
}

/**
 * 搜索
 */
export const fetchSearch = <T = any>(params?: Record<string, any>) => {
    return get<T>(SEARCH_URL, params);
}

/**
 * 获取页脚信息
 */
export const fetchFooter = <T = any>(params?: Record<string, any>) => {
    return get<T>(FOOTER_URL, params);
}

/**
 * 提交订单
 */
export const fetchSubmitOrder = <T = any>(data: FormData) => {
    return post<T>(ADD_ORDER_URL, data, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

/**
 * 获取头部数据
 */
export const fetchHeader = <T = any>(params?: Record<string, any>) => {
    return get<T>(Head, params);
}

/**
 * 随机產品
 */
export const fetchRan = <T = any>(params?: Record<string, any>) => {
    return get<T>(RAN_URL, params);
}

/**
 * 排序
 */
export const fetchSort = <T = any>(params?: Record<string, any>) => {
    return get<T>(SORT_URL, params);
}

/**
 *
 */
export const fetchHot = <T = any>(id: number) => {
    return get<T>(`${HOT_URL}/${id}`);
}
/**
 * 页脚表标签
 */
export const fetchFooterTag = <T = any>(params?: Record<string, any>) => {
    return get<T>(FOOTER_TAG_URL, params);
}
/**
 * 精选
 */
export const fetchRecommend = <T = any>(count : number) => {
    return get<T>(`${CHOICE_URL}/${count}`);
}
